package com.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.health.dao.InformationDao;
import com.health.entity.PageResult;
import com.health.entity.QueryPageBean;
import com.health.entity.Result;
import com.health.pojo.Information;
import com.health.service.InformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Classname InformationServiceImpl
 * @Description TODO
 * @Version 1.0.0
 * @Date 2023/3/20 19:27
 * @Author RainGrd
 */
@Service(interfaceClass = InformationService.class)
@Transactional
@Slf4j
public class InformationServiceImpl implements InformationService {


    @Autowired
    private InformationDao informationDao;

    @Override
    public PageResult queryInformationForPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        List<Information> result = informationDao.selectInformationByCondition(queryPageBean.getQueryString());
        long total = informationDao.selectTotalByCondition(queryPageBean.getQueryString());
        log.info("total:{}", total);
        return new PageResult(total, result);
    }

    @Override
    public Result queryInformationById(Integer id) {
        return Result.success(informationDao.selectInformationById(id));
    }

    @Override
    public int saveInformation(Information information) {
        //填充当前日期
        information.setReleaseTime(new Date());
        return informationDao.insertInformation(information);
    }

    @Override
    public int editInformation(Information information) {
        return informationDao.updateInformation(information);
    }

    @Override
    public int deleteInformation(Integer id) {
        return informationDao.deleteInformation(id);
    }
}
